program optional

    implicit none
    integer :: a

    a = 1

    call incr(a)
    print *, a

    call incr(a, 2)
    print *, a

contains

    pure subroutine incr(a, b)
        integer, intent(inout) :: a
        integer, optional, intent(in) :: b

        if (present(b)) then
            a = a + b
        else
            a = a + 1
        end if

    end subroutine incr

end program optional
!>            2
!>            4